﻿using Compass.Wasm.Shared.Data.Cabins;
using SolidWorks.Interop.sldworks;

namespace Compass.Wpf.SwServices;

public class CabinService : BaseSwService, ICabinService
{
    public CabinService(IContainerProvider provider) : base(provider)
    {
    }
    public void Abd200(ModelDoc2 swModelTop, AssemblyDoc swAssyTop, string suffix, AbdData data)
    {
        //2024.04.01,关于ABD阀固定螺钉的改善建议
        //可以的，那就以250mm这个单位来判断增加螺丝的标准。
        //即250/2=125mm，间距大于125就多加个螺丝。
        //以400X300阀门为例，宽度125*2<300<125*3，螺丝数量=300/125+1=3取整
        //长度螺丝数量 = 400/125+1=4取整

        //最外侧螺丝孔是在角铁上，为脖颈长+26
        var nutOutDis = data.Length + 26d;
        var nutNumber = (int)(nutOutDis/ 150d);//改成了最小间距150，而不是125
        var nutDis = nutOutDis / nutNumber;

        FNHO0136(swAssyTop,suffix, "FNHO0136-1",data.Length,nutDis);

        //最外侧铆钉间距为脖颈长-58
        var rivetOutDis = data.Length - 58d;
        var rivetNumber = (int)(rivetOutDis/ 160d);
        var rivetDis = rivetOutDis / rivetNumber;
        FNHO0134(swAssyTop, suffix, "FNHO0134-1", data.Length, rivetDis,data.Ansul);
        FNHO0135(swAssyTop, suffix, "FNHO0135-2", data.Length, rivetDis);


        FNHE0006(swAssyTop, suffix, "FNHE0006-1", data.Length, 100d, nutDis, data.Ansul);
        FNHE0007(swAssyTop, suffix, "FNHE0007-1", data.Length, 100d, nutDis);
        FNHE0008(swAssyTop, suffix, "FNHE0008-1", 300d, 100d,data.Ansul, data.AnsulDetector);
        FNHE0009(swAssyTop, suffix, "FNHE0009-1", 300d, 100d, data.Ansul, data.AnsulDetector);

    }

    public void Abd300(ModelDoc2 swModelTop, AssemblyDoc swAssyTop, string suffix, AbdData data)
    {
        throw new NotImplementedException();
    }

    #region ABD阀
    private void FNHO0136(AssemblyDoc swAssyLevel1, string suffix, string partName, double length,double nutDis)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@SketchBase", length-4d);

        swModelLevel2.ChangeDim("Dis@SketchNut", nutDis);
        swModelLevel2.ChangeDim("Dis@LPatternNut", nutDis);
    }

    private void FNHO0134(AssemblyDoc swAssyLevel1, string suffix, string partName, double length, double rivetDis,bool ansul)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@SketchBase", length-5d);

        swModelLevel2.ChangeDim("Dis@LPatternRivet", rivetDis);
        if (ansul)
        {
            swCompLevel2.UnSuppress("Ansul");
        }
        else
        {
            swCompLevel2.Suppress("Ansul");
        }
    }

    private void FNHO0135(AssemblyDoc swAssyLevel1, string suffix, string partName, double length, double rivetDis)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@Base-Flange", length-23d);

        swModelLevel2.ChangeDim("Dis@LPatternRivet", rivetDis);
    }


    private void FNHE0006(AssemblyDoc swAssyLevel1, string suffix, string partName, double exhaustSpigotLength, double exhaustSpigotHeight,double nutDis,
        bool ansul)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@Base-Flange", exhaustSpigotLength + 50d);
        swModelLevel2.ChangeDim("Height@SketchBase", exhaustSpigotHeight);
        if (ansul) swCompLevel2.UnSuppress("Ansul");
        else swCompLevel2.Suppress("Ansul");
        //要ABD阀定位孔
        swCompLevel2.UnSuppress("AbdNut");
        swCompLevel2.UnSuppress("LPatternNut");
        swModelLevel2.ChangeDim("Dis@LPatternNut", nutDis);

    }
    private void FNHE0007(AssemblyDoc swAssyLevel1, string suffix, string partName, double exhaustSpigotLength, double exhaustSpigotHeight, double nutDis)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@Base-Flange", exhaustSpigotLength + 50d);
        swModelLevel2.ChangeDim("Height@SketchBase", exhaustSpigotHeight);
        //要ABD阀定位孔
        swCompLevel2.UnSuppress("AbdNut");
        swCompLevel2.UnSuppress("LPatternNut");
        swModelLevel2.ChangeDim("Dis@LPatternNut", nutDis);
    }
    private void FNHE0008(AssemblyDoc swAssyLevel1, string suffix, string partName, double exhaustSpigotWidth, double exhaustSpigotHeight,
        bool ansul, AnsulDetector_e ansulDetector)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@Base-Flange", exhaustSpigotWidth);
        swModelLevel2.ChangeDim("Height@SketchBase", exhaustSpigotHeight);
        
        if (ansul && ansulDetector is AnsulDetector_e.左探测器口 or AnsulDetector_e.两探测器口)
        {
            swCompLevel2.UnSuppress("AnsulDetector");
        }
        else
        {
            swCompLevel2.Suppress("AnsulDetector");
        }
        //要ABD阀定位孔
        swCompLevel2.UnSuppress("AbdNut");
    }
    private void FNHE0009(AssemblyDoc swAssyLevel1, string suffix, string partName, double exhaustSpigotWidth, double exhaustSpigotHeight,
        bool ansul, AnsulDetector_e ansulDetector)
    {
        var swCompLevel2 = swAssyLevel1.UnSuppress(out ModelDoc2 swModelLevel2, suffix, partName, Aggregator);
        swModelLevel2.ChangeDim("Length@Base-Flange", exhaustSpigotWidth);
        swModelLevel2.ChangeDim("Height@SketchBase", exhaustSpigotHeight);
        
        if (ansul && ansulDetector is AnsulDetector_e.右探测器口 or AnsulDetector_e.两探测器口)
        {
            swCompLevel2.UnSuppress("AnsulDetector");
        }
        else
        {
            swCompLevel2.Suppress("AnsulDetector");
        }
        //要ABD阀定位孔
        swCompLevel2.UnSuppress("AbdNut");
    }
    #endregion


}